quick-ini 1.0__tar.gz → 1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: quick_ini
3
- Version: 1.0
3
+ Version: 1.1
4
4
  Summary: A library for reading from and writting to .ini formatted files
5
5
  Home-page:
6
6
  Author: OllieZ-Mods
@@ -1,4 +1,5 @@
1
1
  from urllib.parse import urlparse
2
+ from typing import Type, Any
2
3
 
3
4
  parsed_ini:dict[str,str|int|bool|float|None] = {}
4
5
  error_message:str = ""
@@ -34,7 +35,7 @@ def get_last_error() -> str:
34
35
  """
35
36
  return error_message
36
37
 
37
- def load_file(file_location:str, auto_type_convert:bool = True, empty_default = None) -> bool:
38
+ def load_file(file_location:str, auto_type_convert:bool = True, empty_default:Any = None) -> bool:
38
39
  """
39
40
  Load a ini style file from the file system or from a URL.
40
41
  \nUse get_value() or get_all() to access.
@@ -85,17 +86,23 @@ def load_file(file_location:str, auto_type_convert:bool = True, empty_default =
85
86
  parsed_ini[left] = right
86
87
  return True
87
88
 
88
- def get_value(name:str, default = None):
89
+ def get_value(name:str, default:Any = None, expected_type:Type = None):
89
90
  """
90
91
  Returns the value attached to the given name.
91
92
  \nIf no setting is found, it will return the passed in default
92
93
  Args:
93
94
  name (str): The name of the setting
94
95
  default (Any): What will be returned if nothing is found
96
+ expected_type (Type): Will make sure the returned object is of this Type, otherwise Raise()
95
97
  Return:
96
98
  Any: The value associated with the name
97
99
  Example:
98
100
  >>> get_value("do_debug_logs", False)
99
101
  True
100
102
  """
101
- return parsed_ini.get(name, default)
103
+ value:Any = parsed_ini.get(name, default)
104
+ if(expected_type != None):
105
+ if(not isinstance(value, expected_type)):
106
+ error = f"Expected type '{expected_type.__name__}', instead got '{type(value).__name__}'"
107
+ raise(ValueError(error))
108
+ return value
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: quick_ini
3
- Version: 1.0
3
+ Version: 1.1
4
4
  Summary: A library for reading from and writting to .ini formatted files
5
5
  Home-page:
6
6
  Author: OllieZ-Mods
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="quick_ini",
5
- version="1.0",
5
+ version="1.1",
6
6
  description="A library for reading from and writting to .ini formatted files",
7
7
  long_description=open('README.md').read(),
8
8
  long_description_content_type="text/markdown",
File without changes
File without changes
File without changes
File without changes