[Python-Dev] Re: Feature Request: Adding Way to Annotate Class Variables Distinct from Instance Variables

2022-12-22 Thread Chihiro Sakai
OK, I missed out on [email protected], and now I know this thread is 
off-topic on [email protected].

A bit more clear example of what I want to do is:

```
class Field:
  def __init__(self, desc: str) -> None:
self.desc = desc


class FooMetaType:
  variable_both_class_and_instance: Field

  def __call__(self, value: int) -> 'Foo':
...


class Foo:
  variable_both_class_and_instance: int

  def __init__(self, value: int) -> None:
self.variable_both_class_and_instance = value

Foo: FooMetaType
Foo.variable_both_class_and_instance = Field(desc="descriptive string")

instance = Foo(5)

print(instance.variable_both_class_and_instance)
```

Static typing on this example doesn't work correctly as expected because it 
does not allow overwriting another type over a class declaration.

My point on the example is the tangible value should be assigned to the 
instance variables. Still, on the other hand, I want to give a value denoting 
the variable's metadata to the class variable. From my understanding, these 
variables, like this `variable_both_class_and_instance` in the example, cannot 
be correctly typed.

Thank you for your kindness, I'll repost it to [email protected].
___
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/IDV7E26G4SDUNEGCMFAAMXLO52YQNOPE/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: PEP 701 – Syntactic formalization of f-strings

2022-12-22 Thread Rob Cliffe via Python-Dev

Great stuff! 😁
Rob Cliffe

On 19/12/2022 17:59, Pablo Galindo Salgado wrote:


Hi everyone,

I am very excited to share with you a PEP thatBatuhan Taskaya, 
Lysandros Nikolaou and myself have been working on recently:PEP 701 - 
PEP 701 – Syntactic formalization of f-strings 
.


We believe this will be a great improvement in both the 
maintainability of CPython and the usability of f-strings.


We look forward to hearing what you think about this and to get your 
feedback!


*Here is a TLDR for your convenience:*

  * The PEP proposes a formalized grammar for f-strings in Python by
adding f-strings directly into the Grammar instead of using a
two-pass hand-written parser.
  * This would lift some existing restrictions for f-strings that (we
believe) will improve the user experience with f-strings.
  * Other benefits include:
  o Reduced maintenance costs for f-string parsing code as well as
improved usability for users and library developers.
  o Better error messages involving f-strings by leveraging the
PEG parser machinery.
  o The proposed changes would improve the overall consistency of
the language and provide a way for alternative implementations
to accurately implement f-strings.

*** IMPORTANT: direct all discussions to the discussion thread on 
discourse: 
https://discuss.python.org/t/pep-701-syntactic-formalization-of-f-strings/22046 
***


Thanks a lot, everyone for your time!

Regards from rainy London,
Pablo Galindo Salgado

___
Python-Dev mailing list [email protected]
To unsubscribe send an email [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived 
athttps://mail.python.org/archives/list/[email protected]/message/IU4O3GFGWJ4FWXXC2TVB4CNPZI3KFBQM/
Code of Conduct:http://python.org/psf/codeofconduct/
___
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/S2S2OQNDDSYCC23LBINQZZUCNVYOAEAC/
Code of Conduct: http://python.org/psf/codeofconduct/