geekcomputers/Python · error · AttributeError
Non existing enum
Error message
Non existing enum
What it means
get_word dispatches on a Source enum; if self._source matches neither FROM_INTERNET nor FROM_FILE it raises AttributeError('Non existing enum'). This guards against an invalid, stale, or mocked enum value reaching the dispatcher.
Source
Thrown at Industrial_developed_hangman/src/hangman/main.py:119
self._word_string_to_show = ""
self._guess_attempts_coefficient = 2
self._print_function = pr_func
self._input_function = in_func
self._choice_function = ch_func
def get_word(self) -> str:
# noqa: DAR201
"""
Parse word(wrapper for local and web parse).
:returns str: string that contains the word.
:raises AttributeError: Not existing enum
"""
if self._source == Source.FROM_INTERNET:
return parse_word_from_site()
elif self._source == Source.FROM_FILE:
return parse_word_from_local(self._choice_function)
raise AttributeError("Non existing enum")
def user_lose(self) -> None:
"""Print text for end of game and exits."""
print_wrong(
f"YOU LOST(the word was '{self._answer_word}')", self._print_function
) # noqa:WPS305
def user_win(self) -> None:
"""Print text for end of game and exits."""
print_wrong(f"{self._word_string_to_show} YOU WON", self._print_function) # noqa:WPS305
def game_process(self, user_character: str) -> bool:
# noqa: DAR201
"""
Process user input.
:parameter user_character: User character.
:returns bool: state of game.View on GitHub (pinned to 40f4cd2652)
Solutions
- Always pass a Source enum member: MainProcess(Source.FROM_FILE)
- If Source came from storage/JSON, coerce it back: Source(value) before use
- When adding enum members, update get_word's dispatch (prefer match or dict dispatch)
- In tests, patch parse_word_from_site instead of inventing fake enum values
Example fix
# before source = 'internet' # raw string proc = MainProcess(source) # after from hangman.main import Source proc = MainProcess(Source.FROM_INTERNET)
Defensive patterns
Strategy: type-guard
Validate before calling
from hangman.main import Source assert source in (Source.FROM_INTERNET, Source.FROM_FILE)
Type guard
from enum import Enum
def is_valid_source(value) -> bool:
return isinstance(value, Enum) and value in set(Source) Try / catch
try:
word = get_word()
except AttributeError:
print('invalid word source configured') Prevention
- Only pass Source enum members, never raw strings/ints
- Coerce deserialized values with Source(value)
- Update get_word dispatch whenever Source gains new members
When it happens
Trigger: Constructing MainProcess with a Source member added later/removed, passing a raw string or int instead of a Source enum, or tests passing sentinel values. Because the checks are if/elif over two members, any third value falls through.
Common situations: Extending Source with a new member (e.g. FROM_DATABASE) without updating get_word; serializing/deserializing the enum through JSON so it becomes a string; tests passing fake source values.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- File local_words.txt was not found
- There is no connection to the internet
- Something go wrong with getting the word from site
AI-assisted analysis of geekcomputers/Python@40f4cd2652 (2026-08-27).
Data as JSON: /api/errors/9d43b9dddb696b9d.
Report an issue: GitHub.