<commit_before>import functools
import inspect
import typing


def provider(func=None, *, singleton=False):
	"""
	Decorator to mark a function as a provider.

	Args:
		singleton (bool): The returned value should be a singleton or shared
			instance. If False (the default) the provider function will be
			invoked again for every time it's needed for injection.

	Example:
		@provider
		def myfunc() -> MyClass:
			return MyClass(args)
	"""
	def _add_provider_annotations(wrapper, func):
		wrapper.__di__ = getattr(func, '__di__', {})
		hints = typing.get_type_hints(func)
		wrapper.__di__['provides'] = hints['return']
		wrapper.__di__['singleton'] = singleton

	if func is None:
		def decorator(func):
			@functools.wraps(func)
			def wrapper(*args, **kwargs):
				return func(*args, **kwargs)
			_add_provider_annotations(wrapper, func)
			return wrapper
		return decorator

	@functools.wraps(func)
	def wrapper(*args, **kwargs):
		return func(*args, **kwargs)
	_add_provider_annotations(wrapper, func)
	return wrapper


def inject(*args, **kwargs):
	"""
	Mark a class or function for injection, meaning that a DI container knows
	that it should inject dependencies into it.

	Normally you won't need this as the injector will inject the required
	arguments anyway, but it can be used to inject properties into a class
	without having to specify it in the constructor, or to inject arguments
	that aren't properly type hinted.

	Example:
		@di.inject('foo', MyClass)
		class MyOtherClass: pass
		assert isinstance(injector.get(MyOtherClass).foo, MyClass)
	"""<commit_msg>simplify provider decorator<commit_after>import functools
import inspect
import typing


def _wrap_provider_func(func, di_props):
	hints = typing.get_type_hints(func)
	di_props['provides'] = hints['return']

	if not hasattr(func, '__di__'):
		func.__di__ = {}
	func.__di__.update(di_props)

	return func


def provider(func=None, *, singleton=False):
	"""
	Decorator to mark a function as a provider.

	Args:
		singleton (bool): The returned value should be a singleton or shared
			instance. If False (the default) the provider function will be
			invoked again for every time it's needed for injection.

	Example:
		@provider
		def myfunc() -> MyClass:
			return MyClass(args)
	"""
	di_props = {'singleton': singleton}

	if func is None:
		def decorator(func):
			return _wrap_provider_func(func, di_props)
		return decorator

	return _wrap_provider_func(func, di_props)


def inject(*args, **kwargs):
	"""
	Mark a class or function for injection, meaning that a DI container knows
	that it should inject dependencies into it.

	Normally you won't need this as the injector will inject the required
	arguments anyway, but it can be used to inject properties into a class
	without having to specify it in the constructor, or to inject arguments
	that aren't properly type hinted.

	Example:
		@di.inject('foo', MyClass)
		class MyOtherClass: pass
		assert isinstance(injector.get(MyOtherClass).foo, MyClass)
	"""
{'fraction_non_alphanumeric': 0.09005691329092735, 'fraction_numerical': 0.0, 'mean_word_length': 4.637735849056604, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3128394', 'n_tokens_mistral': 965, 'n_tokens_neox': 884, 'n_words': 334}