Skip to content
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

Feat: Base Class Implemenations #17

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

Nostrademous
Copy link
Contributor

base implemenation of some classes following code_structures.md

@@ -0,0 +1,33 @@
#!/usr/bin/env python3
Copy link
Member

Choose a reason for hiding this comment

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

This does not work well for projects with external dependencies. The system Python interpreter is for system-level scripts. For your own applications, always use a virtual environment.

class Build:
def __init__(self, name: str = "temp") -> None:
self.name = name
self.tree_ref = Tree.Tree()
Copy link
Member

Choose a reason for hiding this comment

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

In Python, every variable is a reference to a value that lives somewhere else. Best to leave out the "ref" part, except when you would actually use weak references.

self.tree_ref = Tree.Tree()
self.player_ref = Player.Player()

def __repr__(self) -> str:
Copy link
Member

Choose a reason for hiding this comment

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

__repr__ functions are intended for debugging only, not for human readable display. That's what __str__ is for. See https://docs.python.org/3/library/functions.html#repr and https://docs.python.org/3/library/functions.html#str

@@ -0,0 +1,33 @@
#!/usr/bin/env python3

# Build Class
Copy link
Member

Choose a reason for hiding this comment

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

Consider replacing this redundant comment with a module-level docstring that describes teh purpose of this module.


# Build Class
#
# Contains:
Copy link
Member

Choose a reason for hiding this comment

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

For a table of contents, you could either use your IDE's conde structure view or extract the structure with an automatic documentation builder tool like Sphinx.

from enum import Enum


class PlayerClasses(Enum):
Copy link
Member

Choose a reason for hiding this comment

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

Consider enum.IntEnum and enum.auto.

self.player_class = player_class
self.ascendancy = ascendancy
self.level = level
self.stats = dict()
Copy link
Member

Choose a reason for hiding this comment

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

Consider dict literals.

# [dict] All Nodes (addressable by Node ID)
# [dict] Allocated Nodes (addressable by Node ID)

_VERSION_ = "3.17"
Copy link
Member

Choose a reason for hiding this comment

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

If this should be a constant that is private to the module, remove the trailing underscore. Trailing underscores are usually uses to avoid name conflicts with built-ins and keywords.

return ret_str


def test() -> None:
Copy link
Member

Choose a reason for hiding this comment

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

Usually, tests are contained in their own file hierarcy, starting from tests/ at the repository root.

Copy link
Member

@ppoelzl ppoelzl left a comment

Choose a reason for hiding this comment

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

Packages and modules should have lowercase names. See https://www.python.org/dev/peps/pep-0008/#package-and-module-names

@@ -0,0 +1,17 @@
# Enumeration Data for Path of Exile constants
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 be a module-level docstring.

[optional set] Minions
"""

from Enumerations import PlayerClasses, PlayerAscendancies
Copy link
Member

Choose a reason for hiding this comment

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

These enums are currently used in a single place. It's best to keep them as local as possible. When they are used by more than one module on the same package, put them in a separate module. When they are used by more than one package, consider reworking the packages or put them in their own package.

[set] Allocated Nodes (addressable by Node ID)
"""

_VERSION_ = "3.17"
Copy link
Member

Choose a reason for hiding this comment

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

Consider storing version numbers as tuples.

Copy link

Choose a reason for hiding this comment

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

Could you supply an example ? I'm too new to Python to understand what that means.

@pHiney
Copy link

pHiney commented Jun 25, 2022

Why are you using enumerations and not dictionaries

class PlayerClasses(Enum):
    SCION = 0
    MARAUDER = 1
    RANGER = 2
    WITCH = 3
    DUELIST = 4
    TEMPLAR = 5
    SHADOW = 6

I setup the colorCodes as a dictionary

colorCodes = {
    "NORMAL": "#000000",
    "MAGIC": "#8888FF",
    "RARE": "#FFFF77",

I'm not sure of the advantages of either.

X

@ppoelzl
Copy link
Member

ppoelzl commented Jun 26, 2022

PEP 345 lists some reasons for using enums. Further advantages:

  • Enums have a distinct type
  • Dicts are stringly typed, so enums avoid typos
  • Enum variants are discoverable and you can auto-complete them
  • Nicer syntax: dot access vs key access; allows for automatic enumeration.
  • Stronger type guarantees for subtypes like enum.IntEnum (comparable to typing.TypedDict, but without the need for annotations)

@pHiney
Copy link

pHiney commented Jun 27, 2022

PEP 345 lists some reasons for using enums. Further advantages:

Currently I'm filling a combobox with

        self.colour_combo_box.addItems(color_codes.keys())

Which is super convenient.
image

Whilst the color_codes naturally would be good as enums, what hoops to to go through to fill the combobox ? Or is there a different way to choose colours ?

x

@ppoelzl
Copy link
Member

ppoelzl commented Jun 27, 2022

You can iterate over an enum's variants and get their names:

self​.​colour_combo_box​.​addItems​(​[colour.name for colour in ColourCodes])

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.

3 participants