Comments (2)
You can already add a default to your implementation of __getitem__
, but there is no way to use the subscript syntax to call it with zero arguments. I assume you are suggesting that X[]
would be changed to call X.__getitem__()
.
That would be a change to the grammar, so definitely not a minor feature that we can accept without prior discussion. In fact, it would probably need a PEP.
Your link shows 30k uses of [()]
. That's a lot, but in https://discuss.python.org/t/implicit-tuple-return-type/52903/61 you found more than 30 million uses of x[a, b]
—indicating that the x[()]
syntax is not especially common. I glanced through the first few results; some are uses of the empty tuple type tuple[()]
, others are in various array or tensor libraries. I can't speak for the latter, but from a typing perspective I think tuple[()]
is a clearer spelling for the empty tuple type than tuple[]
.
from cpython.
https://discuss.python.org/t/allow-zero-arguments-for-subscript-syntax/53084
from cpython.
Related Issues (20)
- `contextlib.suppress` converts instances of a subtype of `ExceptionGroup` to an instance of the `ExceptionGroup` class HOT 2
- Add job to `jit.yml` to build and test with `--disable-gil`
- Incompatibility between _decimal and _pydecimal: tp_name for Decimal
- Python float calculation error HOT 2
- IDLE: Menu fonts too small HOT 1
- `get_origin(str|None) != get_origin(Union[str,None])` HOT 4
- Break up _pyrepl tests HOT 1
- '\040' instead of space in repl history on macOS with 3.13 or main branch HOT 2
- Unexpected name mangling behavior with generics HOT 1
- Resolve deprecation warnings in Docs/tools HOT 1
- REPL cursor is rendered offset in VSCode on WSL HOT 4
- Add c-api to set callback function on enter and exit of PyContext
- '_PyLong_NumBits': identifier not found in 3.13 HOT 3
- Out-of-memory when loading a Plist
- Make `Py_BEGIN_CRITICAL_SECTION()` and `Py_END_CRITICAL_SECTION()` public in the non-limited C API
- Add a ctypes.util function to list loaded shared libraries
- Add UOp Pair Compatibility to PyStats
- Adding >1 new line within a codeblock doesn't correctly match the indentation HOT 1
- Increase coverage of test_pyrepl HOT 1
- Deadlock in `pool_in_threads.py` (`test_multiprocessing_pool_circular_import`) in free-threaded build HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cpython.