On Tue, Aug 31, 2021 at 10:25 AM Nick Parlante <n...@cs.stanford.edu> wrote:
>
> I understand that Python itself should work with classes with any sort of 
> crazy semantics, and I appreciate your spelling it out. We could say that the 
> bar for the Python implementation is the highest, since who knows what 
> experimental == someone might cook up playing around, and you would like the 
> underlying Python layers to hold up correctly no matter what.
>
> Now I chose the lines from the Python modules as just a random source of PEP8 
> compliant code, but I think I confused my message there, which was about 
> "regular" not Python implementation code.
>
>> Here is my proposal:
>>
>> Add the following parenthetical to the mandatory-is rule: (this rule
>> is optional for code that is not part of an implementation of Python).
>
>
> So if I have a line like this
>
>     if x == None:
>
> and this is in a Python program that is using regular old Python classes like 
> int and list and dict and whatever. It is not importing a class with weird == 
> semantics. We would agree, that == is going to work perfectly in that case. 
> My code is relying on the == of the classes it uses, and that is sensible.
>

You don't seem to understand the full significance of "function
parameter", then. Any time you're accepting a parameter from someone
else, it COULD BE something like this. You can't know that it is a
"regular old Python class" or anything else. Case in point: one of
your examples, ast.py, first instance of " is " in the code:

def parse(source, filename='<unknown>', mode='exec', *,
          type_comments=False, feature_version=None):
    ...
    if isinstance(feature_version, tuple):
        major, minor = feature_version  # Should be a 2-tuple.
        assert major == 3
        feature_version = minor
   elif feature_version is None:
        feature_version = -1

If you "import ast; ast.parse(...)", you can pass it *any Python
object* as feature_version. ANY. It checks if it's a tuple (or a
subclass thereof), and then, if it isn't that, checks to see if it is
precisely the sentinel None. (I'm not sure why the checks are in that
order. Given that the default argument is None, it would seem likely
that the bulk of calls will have None, so I personally would have
checked for None first and tuple second.)

Might be time that this moves off python-ideas. I don't think PEP 8 is
going to change to encourage a buggy practice.

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/7BGYNK4WI62S3YSYJRYOM25NAQAJ5CPP/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to