Comments (8)
I actually just implemented something along the lines for 3.14:
- Add an extra integer field to
_symtable_entry
objects of the following type:
/* Additional flags that are set temporarily on a symtable object.
*
* Those flags are only used to add some information on the current context.
*/
typedef enum _extra_flags {
// Mutually exclusive flags indicating which component of
// a type parameters block (PEP 695) is being processed.
InTypeVarBound = 1,
InTypeVarConstraint = 2,
InTypeVarDefault = 4,
} _Py_extra_fls;
Here, it's only used for adding some extra information for the "component" being processed in a type parameter block, but it can be used for other kind of blocks in the future. I also tried a first implementation where you add more block types but it became a bit messy...
By the way, since I didn't see anything for distinguishing between bounds and constraints, I assumed that a tuple expression is always considered a constraints but if this is not the case (namely, you could have cases where the expression's kind is Tuple_kind
but we are actually dealing with a bound, then please let me know how I can distinguish and test those cases).
I'm sending the PR in a few moments (I'll just skip the news and changes for now, since this is something I can do later).
from cpython.
Yes, I think it should say e.g. "yield expression cannot be used in a ParamSpec default".
from cpython.
Fixed in 3.13 and 3.14. There is still a bug in 3.12 where it says "bound" for constraints, but I'm OK with that.
from cpython.
I know that you self-assigned that task, but can I perhaps help for this one if you are not in a hurry for the latter? I'd be interested in knowing how to make it work.
from cpython.
Sure, this issue would be a good way to get some familiarity with the symtable code. I partly self-assigned this because the solution is likely to create some conflicts with #119361, and I want to get that landed first :). But the conflict is likely manageable, so feel free to get started now.
The solution is going to look a little different on 3.12 (which has only TypeVar bounds and constraints), 3.13 (which adds TypeVar/ParamSpec/TypeVarTuple defaults), and 3.14 (which will implement PEP 649, using annotation scopes in more contexts).
I think there's two approaches we can take to solving the issue:
- Give a more generic error, maybe just "yield expression cannot be used here". That's easier to implement since we don't have to keep track of exactly what flavor of annotation scope we're in, but the error becomes more generic.
- Make the errors more specific. When I implemented PEP 695, I attempted to do this by adding to the
_Py_block_ty
enum. However, now that we have type parameter defaults too, we'd have to add another three entries to that enum, which feels bad for maintenance. Maybe alternatively, we could add a new string field to thePySTEntryObject
struct to hold a string representing the kind of scope we're in. Then we can just pass that string when entering the block and unify a couple of the entries in the_Py_block_ty
enum.
from cpython.
InTypeVarDefault
This isn't enough, because ParamSpec and TypeVarTuple can also have defaults.
I assumed that a tuple expression is always considered a constraints
That is correct; it's constraints if the top level is a Tuple and a bound otherwise.
from cpython.
This isn't enough, because ParamSpec and TypeVarTuple can also have defaults.
Oh, yes, I should maybe change the naming then (actually, ParamSpec and TypeVarTuple are correctly handled but I just badly named the fields).
from cpython.
Actually, what kind of error should I use for a TypeVarTuple and ParamSpec? should I also change the "in a TypeVar default" into "in a TypeVarTuple/ParamSpec default"? (same question for class definitions and so on).
from cpython.
Related Issues (20)
- logging.config: configuring root through dictConfig won't update already existing loggers HOT 1
- AttributeError: 'datetime.datetime' object has no attribute 'times' HOT 1
- [CI/CD] allow to skip tests that are know to lack a C (or Python) implementation. HOT 5
- a biit better example in pathlib docs - maybe include example path that involves file in a folder(s)? HOT 1
- Security branches: Consider fixing the documentation or adding a notice banner HOT 1
- New REPL omits local variables when running ./python -i script.py HOT 2
- importlib.metadata test fixtures should prefer test.support fixtures
- Lacking description of how to correctly implement indexing syntax support.
- Rewrite asyncio subprocesses without child watchers
- Unpickling Exceptions with keyword arguments in multiprocessing throws an error HOT 12
- Reference leak in `_contextvars.Context.run()`
- Allow one to use build.bat to skip building test project files entirely. HOT 4
- CANT FIND THE FUCKING DOWNLOAD BUTTON HOT 2
- Typo in the documentation of the `cmd` parameter of `ftplib.FTP.retrbinary()` HOT 1
- ios buildbot failure: `enclose 'sqlite3_create_window_function' in a __builtin_available check to silence this warning` HOT 1
- generator frame type should not be PyObject*[]
- `subprocess.run` docs should recommend copying `os.environ` on Windows HOT 3
- `faulthandler` itself crashes in free-threading build (in `_Py_DumpExtensionModules`)
- Some Runtime Finalization Constraints Are Not Enforced Nor Documented
- asyncio REPL fails to run with TERM=dumb or PYTHON_BASIC_REPL in 3.13.0b2 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.