Skip to content

Conversation

@nicoonoclaste
Copy link
Collaborator

Following a discussion with @astronouth7303.

@nicoonoclaste
Copy link
Collaborator Author

Right, this fails on 3.6 because dataclasses was introduced in 3.7.
I guess this is a reasonable justification to reject for now, or at least delay until there are other/stronger reasons to require 3.7 or later?

@nicoonoclaste
Copy link
Collaborator Author

PS: There is a version of dataclasses on PyPI, which should work on 3.6.

@AstraLuma
Copy link
Member

Add dataclasses; python_version < '3.7' to the requirements list.

Copy link
Member

@AstraLuma AstraLuma left a comment

Choose a reason for hiding this comment

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

I would love to see a utility method instead of requiring the use of dataclasses.replace()--especially since it doesn't actually replace anything. Some name ideas:

  • .update()
  • .mutate()
  • .change()

return _find_lowest_type(left, right)


@dataclass(eq=False, frozen=True, init=False, repr=False)
Copy link
Member

Choose a reason for hiding this comment

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

This should probably have eq=True for reasons of hashing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That should result in a TypeError since Vector2 defines it's own __eq__.

Moreover, I don't think we can make it an hashable type, as AFAIK hash(vector) == hash(vector_like) would need to hold wherever vector == vector_like.

Copy link
Member

Choose a reason for hiding this comment

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

I'm.... not certain off-hand.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, for this you want to key the same, two equal things must hash the same.

In this case, I don't think we want to key the same to anything not an actual vector? And this becomes a problem not because we expect users to key dictionaries on vectors, but because of things like functools.lru_cache, which use dictionaries under the hood.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it will definitely break anything that expects to index something off a vector-like; it's also a violation of the hash protocol, so I'd really rather not make it hashable.

OK with proceeding without adding __hash__?

@nicoonoclaste
Copy link
Collaborator Author

@astronouth7303 I didn't suggest requiring users to know about dataclass, but more that update = dataclasses.replace would be a nice convenience function to expose.

- Use the float() builtin, instead of calling a dunder directly.
  Since it raises ValueError, we can clean up the exception handling.

- Only do the conversions in the Vector2 constructor; Vector2.convert
  doesn't need to coerce to float before calling the constructor.
This dependency is optional in Python 3.7 or later,
as [PEP 557] made it part of the standard library.

[PEP 557]: https://www.python.org/dev/peps/pep-0557/
@nicoonoclaste
Copy link
Collaborator Author

nicoonoclaste commented Jan 15, 2019

OK, rebased now that CI was green again and that your comments were handled (except for update).

@AstraLuma AstraLuma merged commit ee409f2 into ppb:master Jan 18, 2019
@AstraLuma AstraLuma mentioned this pull request Jan 18, 2019
@nicoonoclaste nicoonoclaste deleted the dataclasses branch January 18, 2019 05:43
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.

2 participants