-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test the Union Operator on dictionaries #53
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
Hi there @brocla! Thank you for this. 😄 I am running behind in life, so haven't gotten to this or your previous PR -- but hopefully will do so before EOD tomorrow. -B |
Uh. Oh. This is currently failing CI. I think that's because the I will check later today (or if you have time, you can) -- but we probably need to slightly rewrite the ChatGPT example. Its going off of historical/bad data. 😄 |
No problem. Life comes first.
I'll take a look at rewriting with tomlib.
Thanks
Kevin
…On Tue, Mar 12, 2024, 5:45 PM BethanyG ***@***.***> wrote:
Uh. Oh. This is currently failing CI. I *think* that's because the toml
library has been deprecated for Python, and Python 3.11+ now has the
tomlib <https://docs.python.org/3.11/library/tomllib.html> module in its
place.
image.png (view on web)
<https://github.com/exercism/python-representer/assets/5923094/539779fa-7e39-4ab5-b8b6-7688658ab6c2>
I will check later today (*or if you have time, you can*) -- but we
probably need to slightly rewrite the ChatGPT example. Its going off of
historical/bad data. 😄
—
Reply to this email directly, view it on GitHub
<#53 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACBULKRFRADZMIWCF5SOEM3YX6HTNAVCNFSM6AAAAABESWKK3CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOJSG42DONBVG4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
- delete leading and trailing blank lines
Hmmm....
I converted `toml` to `tomlib` and deleted the leading/trailing blank lines
in the test file. Now it works.
So that's good...
Kevin
…On Tue, Mar 12, 2024 at 7:11 PM Kevin Brown ***@***.***> wrote:
No problem. Life comes first.
I'll take a look at rewriting with tomlib.
Thanks
Kevin
On Tue, Mar 12, 2024, 5:45 PM BethanyG ***@***.***> wrote:
> Uh. Oh. This is currently failing CI. I *think* that's because the toml
> library has been deprecated for Python, and Python 3.11+ now has the
> tomlib <https://docs.python.org/3.11/library/tomllib.html> module in its
> place.
>
> image.png (view on web)
> <https://github.com/exercism/python-representer/assets/5923094/539779fa-7e39-4ab5-b8b6-7688658ab6c2>
>
> I will check later today (*or if you have time, you can*) -- but we
> probably need to slightly rewrite the ChatGPT example. Its going off of
> historical/bad data. 😄
>
> —
> Reply to this email directly, view it on GitHub
> <#53 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ACBULKRFRADZMIWCF5SOEM3YX6HTNAVCNFSM6AAAAABESWKK3CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOJSG42DONBVG4>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Added adapted examples from Mecha Munch Management
, and had a few other suggestions/suggested removals. LMK if you have questions or issues.
I can merge later today, after we finalize things. 😄
test/example-uniondict-normalization/example_uniondict_normalization.py
Outdated
Show resolved
Hide resolved
test/example-uniondict-normalization/example_uniondict_normalization.py
Outdated
Show resolved
Hide resolved
test/example-uniondict-normalization/example_uniondict_normalization.py
Outdated
Show resolved
Hide resolved
test/example-uniondict-normalization/example_uniondict_normalization.py
Outdated
Show resolved
Hide resolved
Be explict about dictionaries.
Hi Bethany,
Yes, it might be time to let go. We can use three exercises that we have
already written for unions. They will protect us in the case that an
`astor` version of the Representer sneaks back in.
BTW
I installed an older version of python (3.8.13) to show that ast would
not parse and unparse a tiny example. But it failed for an unexpected
reason: `ast` has no attribute `unparse` !?!
It turns out that `unparse()` is new in python 3.9. I don't think the
python developers are going to spend much time making unparse work
for releases that are older than the feature.
>> import ast
>> ast.unparse(ast.parse('{} | {}'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'ast' has no attribute 'unparse'
…On Fri, Mar 15, 2024 at 2:41 AM BethanyG ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In test/example-uniondict-normalization/example_uniondict_normalization.py
<#53 (comment)>
:
> +""" Examples from PEP584 - Add Union Operators To dict"""
+d = {'spam': 1, 'eggs': 2, 'cheese': 3}
+e = {'cheese': 'cheddar', 'aardvark': 'Ethel'}
+# d | e # Representer fails, result must be assigned. # TODO Fix this ????
+# e | d # Representer fails
+x = d | e # {'spam': 1, 'eggs': 2, 'cheese': 'cheddar', 'aardvark': 'Ethel'}
+y = e | d # {'cheese': 3, 'aardvark': 'Ethel', 'spam': 1, 'eggs': 2}
+d |= e # {'spam': 1, 'eggs': 2, 'cheese': 'cheddar', 'aardvark': 'Ethel'}
Ugh. Whelp, that was ... fun? *Actually, it wasn't.*
So.
Did some testing and some digging, and it appears that ast.parse(feature_version=(<python
version>)) is somewhat flakey/problematic/erratic. You know you're in
trouble when you find open issues around changing the docs to be really
clear about *"best effort"*
<https://cpython-previews--115980.org.readthedocs.build/en/115980/library/ast.html#ast.parse>
.
When I tested using 3.8, 3.9, 3.10 and 3.11, it appeared the only true
determiner of the AST representation was the main Python version. Setting feature_version=(<some
version>) did not appear to have a major effect on AST parsing. Now, I am
pretty tired so I will retry after some sleep - but its looking pretty grim.
The other thing that adds grimness are the following issues I found in the
cpython repo:
1. cpython issue #115881 comments
<python/cpython#115881 (comment)>
2. mypy issue #16945 <python/mypy#16945>
3. cpython issue #84794
<python/cpython#84794>
4. cpython issue #115881
<python/cpython#115881>
5. cpython issue #115980
<python/cpython#115980>
Looks like something to do with the rewrite of the Python parser, which
happened in Python 3.9 (PEP Here <https://peps.python.org/pep-0617/>).
There is now a sharp before PEG and after PEG -- and so that nice little
flag isn't really set up to switch to an old parser, and so makes a ...
guess? And that guess favors later syntax -- at least for | and |=. If
you read some of the issues above, it does quite the opposite for other
features. 🤦🏽♀️
That all told, I still think having a test in there is worth it ... but
we're probably going to have to let go of truly verifying it, unless we
want to set up a Python version matrix. Again - I am tired, so will need to
ponder in the morning.
—
Reply to this email directly, view it on GitHub
<#53 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACBULKQZ34QNT6TGTOPTS23YYKXZLAVCNFSM6AAAAABESWKK3CVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTSMZYGM3TKNZTGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
test/example-uniondict-normalization/example_uniondict_normalization.py
Outdated
Show resolved
Hide resolved
…zation.py The second argument here needs to be an iterable, and dicts only iterate over keys, but we need keys and values.
Yup. 💙 I also ran into that. And since 3.7 is already EOL, and 3.8 is due to EOL in October, well.... So I agree: we have some good examples, and we've both beaten and tested the "dead horse", so to speak. 😆 I am going to merge as soon as I fix the CI. |
Due to some small code review changes, had to re-record the representation.
Yeah! Great news. Thank you.
Kevin
... I'll go start another one.
…On Fri, Mar 15, 2024, 4:09 PM BethanyG ***@***.***> wrote:
Merged #53 <#53> into
main.
—
Reply to this email directly, view it on GitHub
<#53 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACBULKQPTZINU5RBBVGVA2DYYNWQVAVCNFSM6AAAAABESWKK3CVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJSGEZTOMJZGYYTINQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Hello @BethanyG . This PR has four code snippets to test the union operator ( | and |= ) on dictionaries.
a) I got chatGPT to suggest an example :-) I included my prompt in the file. It is a function to merge user settings with some default settings.
b) This one comes from examples in PEP584 (Add Union Operators To dict).
c) The third example comes from the Cpython unit tests.
d) The last one comes from the
alphametrics
exercise. I modified a call to the .union() method, to use the operator instead.