10000 Pass AbstractSets to Transaction by Goorzhel · Pull Request #10 · jmgilman/beancount-stubs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Pass AbstractSets to Transaction #10

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

Merged
merged 1 commit into from
Jul 28, 2024
Merged

Pass AbstractSets to Transaction #10

merged 1 commit into from
Jul 28, 2024

Conversation

Goorzhel
Copy link
Contributor

Matches upstream code. Fixes #4.

@@ -129,8 +130,8 @@ class Transaction:
flag: Flag
payee: Optional[str]
narration: str
tags: Optional[set]
links: Optional[set]
tags: FrozenSet
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only EMPTY_SET is a frozen set - probably to make sure it stays empty :)

The Transaction's definition specifies Set here and the "sanity checker" accepts both Set and FrozenSet here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, joke's on me—when I said "matches upstream code" I was looking at master.

How about:

Suggested change
tags: FrozenSet
tags: FrozenSet | set

Or, although that allow_none_for_tags_and_links switch defaults to False:

Suggested change
tags: FrozenSet
tags: FrozenSet | set | None

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say let's go with None being a part of the set. And no worries about the branch mismatch, been in the same position a week ago, writing my own importer... :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, since I'm annotating args, the docs say I should use AbstractSet.

>>> from typing import AbstractSet
>>> issubclass(set, AbstractSet)
True
>>> issubclass(frozenset, AbstractSet)
True

Although AbstractSet is deprecated since 3.9, most of typing is too, so I won't worry about that yet.

Should I fix Document accordingly in this or another PR?

@yacoob yacoob changed the base branch from master to dev July 28, 2024 14:03
@yacoob yacoob force-pushed the dev branch 4 times, most recently from 5b4828c to 5872994 Compare July 28, 2024 15:44
This way, `frozenset`s (like `EMPTY_SET`) are considered valid.

They're `Optional` because Beancount can occasionally be convinced to
allow `None`s into these fields:
https://github.com/beancount/beancount/blob/2.3.6/beancount/core/data.py#L500-L502
@Goorzhel Goorzhel changed the title Pass frozensets to Transaction Pass AbstractSets to Transaction Jul 28, 2024
@yacoob yacoob merged commit f2f7af1 into jmgilman:dev Jul 28, 2024
3 checks passed
yacoob pushed a commit that referenced this pull request Aug 5, 2024
This way, `frozenset`s (like `EMPTY_SET`) are considered valid.

They're `Optional` because Beancount can occasionally be convinced to
allow `None`s into these fields:
https://github.com/beancount/beancount/blob/2.3.6/beancount/core/data.py#L500-L502
@Goorzhel Goorzhel deleted the frozenset branch September 5, 2024 07:08
@Goorzhel Goorzhel restored the frozenset branch December 19, 2024 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Argument 6/7 to "Transaction" has incompatible type "frozenset[Any]"; expected "set[Any] | None"
2 participants
0